package com.zzyl.service.impl;

import com.zzyl.dto.LoginDto;
import com.zzyl.mapper.SystemUserMapper;
import com.zzyl.service.SystemUserService;
import com.zzyl.utils.JwtUtil;
import com.zzyl.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class SystemUserServiceImpl implements SystemUserService {
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Override
    public UserVo login(LoginDto loginDto) {
        UserVo userVo = systemUserMapper.getByUserNameAndPassword(loginDto.getUsername(),loginDto.getPassword());
        if(userVo!= null){
            Map<String, Object> map = new HashMap<>();
            map.put("id",userVo.getId());
            map.put("username",userVo.getUsername());
            String jwt = JwtUtil.createJWT("hina",3600000,map);
            userVo.setUserToken(jwt);
            return userVo;
        }else {
            return null;
        }

    }
}
